const {nextTick, createApp, ref, onMounted, computed, onBeforeUnmount} = Vue;
const {ElDialog, ElButton, ElSelect, ElOption, ElIcon} = ElementPlus;

const Bell = {
    template: '<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em"><path d="M816 768h-24V428c0-141.1-104.3-257.8-240-277.2V112c0-22.1-17.9-40-40-40s-40 17.9-40 40v38.8C336.3 170.2 232 286.9 232 428v340h-24c-17.7 0-32 14.3-32 32s14.3 32 32 32h168c0 53 43 96 96 96s96-43 96-96h168c17.7 0 32-14.3 32-32s-14.3-32-32-32zM512 888c-26.5 0-48-21.5-48-48h96c0 26.5-21.5 48-48 48z" fill="currentColor"></path></svg>'
};

const Monitor = {
    template: '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em"><path d="M20 3H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h6v2H8v2h8v-2h-2v-2h6c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 12H4V5h16v10z" fill="currentColor"></path></svg>'
};

const Warning = {
    template: '<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em"><path d="M955.7 856l-416-720c-6.2-10.7-16.9-16-27.7-16s-21.6 5.3-27.7 16l-416 720C56 877.4 71.4 904 96 904h832c24.6 0 40-26.6 27.7-48zM480 416c0-4.4 3.6-8 8-8h48c4.4 0 8 3.6 8 8v184c0 4.4-3.6 8-8 8h-48c-4.4 0-8-3.6-8-8V416zm32 352a48.01 48.01 0 0 1 0-96 48.01 48.01 0 0 1 0 96z" fill="currentColor"></path></svg>'
};

const Tickets = {
    template: '<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em"><path d="M224 160a64 64 0 0 0-64 64v576a64 64 0 0 0 64 64h576a64 64 0 0 0 64-64V224a64 64 0 0 0-64-64H224zm0-64h576a128 128 0 0 1 128 128v576a128 128 0 0 1-128 128H224A128 128 0 0 1 96 800V224A128 128 0 0 1 224 96z" fill="currentColor"></path><path d="M352 256h320q32 0 32 32t-32 32H352q-32 0-32-32t32-32zm0 192h320q32 0 32 32t-32 32H352q-32 0-32-32t32-32zm0 192h320q32 0 32 32t-32 32H352q-32 0-32-32t32-32z" fill="currentColor"></path></svg>'
};

const SetUp = {
    template: '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em"><path d="M12 15.5A3.5 3.5 0 0 1 8.5 12A3.5 3.5 0 0 1 12 8.5a3.5 3.5 0 0 1 3.5 3.5a3.5 3.5 0 0 1-3.5 3.5m7.43-2.53c.04.32.07.64.07.97c0 1.07-.16 2.12-.46 3.12c-.79.26-1.57.44-2.34.58c-.18-.55-.5-1.03-.92-1.42c.27-.16.52-.35.73-.56c.31-.31.58-.66.8-1.04c.4.09.81.13 1.22.13c.38 0 .75-.04 1.1-.12M4.53 20.95c.26.79.54 1.57.58 2.34c-1.07.3-2.12.46-3.11.46a9.94 9.94 0 0 1-1-.06c.12-.36.12-.73.12-1.12c0-.43-.05-.85-.13-1.25c.38-.22.73-.49 1.04-.8c.21-.21.4-.46.56-.73c-.39-.42-.87-.74-1.42-.92c.14-.77.32-1.55.58-2.34c.55.18 1.03.5 1.42.92c-.16.27-.35.52-.56.73c-.31.31-.66.58-1.04.8c.09.4.13.82.13 1.22c0 .38-.04.75-.12 1.1M12 6C7.03 6 3 10.03 3 15s4.03 9 9 9s9-4.03 9-9s-4.03-9-9-9m0 16c-3.86 0-7-3.14-7-7s3.14-7 7-7s7 3.14 7 7s-3.14 7-7 7m3.44-12.73c.4.09.81.13 1.22.13c.38 0 .75-.04 1.1-.12c-.14-.77-.32-1.55-.58-2.34c-.55.18-1.03.5-1.42.92c.27.16.52.35.73.56c.31.31.58.66.8 1.04c-.4.09-.81.13-1.22.13c-.38 0-.75-.04-1.1-.12c.26.79.44 1.57.58 2.34c.55-.18 1.03-.5 1.42-.92a5 5 0 0 0-.73-.56c-.31-.31-.66-.58-1.04-.8c-.09-.4-.13-.82-.13-1.22c0-.38.04-.75.12-1.1c-.79-.26-1.57-.44-2.34-.58c-.18.55-.5 1.03-.92 1.42c.27-.16.52-.35.73-.56c-.31-.31-.58-.66-.8 1.04c-.4-.09-.81-.13-1.22-.13c-.38 0-.75.04-1.1.12c.14.77.32 1.55.58 2.34c.55-.18 1.03-.5 1.42-.92c.16.27.35.52.56.73c.31.31.66-.58 1.04-.8c-.09-.4-.13-.82-.13-1.22c0-.38.04-.75.12-1.1c.79-.26 1.57-.44 2.34-.58c.18-.55.5-1.03.92-1.42c-.27-.16-.52-.35-.73-.56c-.31-.31-.58-.66-.8 1.04c-.4-.09-.81-.13-1.22-.13c-.38 0-.75.04-1.1.12c.26.79.44 1.57.58 2.34c.55-.18 1.03-.5 1.42-.92c.16.27.35.52.56.73c.31.31.66-.58 1.04-.8c-.09-.4-.13-.82-.13-1.22c0-.38.04-.75.12-1.1c.79-.26 1.57-.44 2.34-.58c.18-.55.5-1.03.92-1.42c-.27-.16-.52-.35-.73-.56c-.31-.31-.58-.66-.8 1.04c-.4-.09-.81-.13-1.22-.13c-.38 0-.75.04-1.1.12c.26.79.44 1.57.58 2.34c.55-.18 1.03-.5 1.42-.92c.16.27.35.52.56.73c.31.31.66-.58 1.04-.8c-.09-.4-.13-.82-.13-1.22c0-.38.04-.75.12-1.1c.79-.26 1.57-.44 2.34-.58c.18-.55.5-1.03.92-1.42c-.27-.16-.52-.35-.73-.56c-.31-.31-.58-.66-.8 1.04z" fill="currentColor"></path></svg>'
};

const Connection = {
    template: '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em"><path d="M20 18v1a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-1a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1zM3 12a1 1 0 0 1 1-1h16a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-1zm18-6v1a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1h16a1 1 0 0 1 1 1z" fill="currentColor"></path></svg>'
};

const SuccessFilled = {
    template: '<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em"><path d="M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896zm-55.808 536.384-99.52-99.584a38.4 38.4 0 1 0-54.336 54.336l126.72 126.72a38.272 38.272 0 0 0 54.336 0l262.4-262.464a38.4 38.4 0 1 0-54.272-54.336L456.192 600.384z" fill="currentColor"></path></svg>'
};

const WarningFilled = {
    template: '<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em"><path d="M512 64a448 448 0 1 1 0 896A448 448 0 0 1 512 64zm32 192a32 32 0 0 0-64 0v320a32 32 0 0 0 64 0V256zm-32 448a48 48 0 1 0 0-96 48 48 0 0 0 0 96z" fill="currentColor"></path></svg>'
};

createApp({
    components: {
        ElDialog,
        ElButton,
        ElSelect,
        ElOption,
        ElIcon,
        Bell,
        Monitor,
        Warning,
        Tickets,
        SetUp,
        Connection,
        SuccessFilled,
        WarningFilled,
        // 新增组件
        User,
        Cpu,
        Delete
    },
    setup() {
        return {
            // 重要组件
            ...ImportantSetup(),
            // AI聊天相关
            ...AIChatSetup(),
        };

    }
}).mount('#app');

// 初始化特征分析模块
/*document.addEventListener('DOMContentLoaded', function() {
    // 等待一段时间确保所有元素都已加载
    console.log("等待一段时间确保所有元素都已加载")
    setTimeout(() => {
        // 启动所有特征分析模块的自动更新
        console.log("timeDomainChart:", timeDomainChart,"frequencyChart:", frequencyChart," stftChart:", stftChart," waveletChart:", waveletChart)
        if (typeof timeDomainChart !== 'undefined' && timeDomainChart.chartElement) {
        console.log("启动所有特征分析模块的自动更新")
            timeDomainChart.startAutoUpdate();
        }

        if (typeof frequencyChart !== 'undefined' && frequencyChart.chartElement) {
            frequencyChart.startAutoUpdate();
        }

        if (typeof stftChart !== 'undefined' && stftChart.chartElement) {
            stftChart.startAutoUpdate();
        }

        if (typeof waveletChart !== 'undefined' && waveletChart.chartElement) {
            waveletChart.startAutoUpdate();
        }
    }, 100); // 延迟100毫秒确保DOM完全加载
});*/

// 页面卸载时停止自动更新
window.addEventListener('beforeunload', function() {
    if (typeof timeDomainChart !== 'undefined') {
        timeDomainChart.stopAutoUpdate();
    }
    
    if (typeof frequencyChart !== 'undefined') {
        frequencyChart.stopAutoUpdate();
    }
    
    if (typeof stftChart !== 'undefined') {
        stftChart.stopAutoUpdate();
    }
    
    if (typeof waveletChart !== 'undefined') {
        waveletChart.stopAutoUpdate();
    }
});
